<template>
    <div>
        <div class="index">
            <!-- 顶部 -->
            <van-sticky>
                <van-nav-bar title="课程列表"></van-nav-bar>
        </van-sticky>
            
        </div>
    </div>
    <div class="films" ref="filmsBox">
        <!-- 课程推荐 -->
        <div class="item" @click="courseDetail(item.id)" v-for="(item, index) in courseList" :key="index">
            <div class="left">
                <img :src="item.courseCover" />
            </div>
            <div class="middle">
                <div>{{ item.courseName }}</div>
                <!-- <div>
                    <span>讲师：</span>
                    <span>{{ item.createUser }}</span>
                </div> -->
                <div>更新人：{{ item.updateUser }}</div>
                <!-- <div>{{ item.createTime }}</div> -->
            </div>
            <div class="right">
                <span>参与</span>
            </div>
        </div>
    </div>
</template>
    
<script setup lang='ts'>
import { ref, onUnmounted, onMounted } from 'vue'
import { getCourse } from '../api/api'
import { useRouter } from 'vue-router';

// import images from "../assets/images/"
//  刷新
let loadingTag = ref<boolean>(true);
let imageError= new URL("../assets/images/imageError.jpg",import.meta.url).href
const router = useRouter()
const courseDetail = (courseId: any) => {
    // 进行路由跳转
    router.push({ path: "/courseDetail/courseWare", query: { params: courseId } })
};


const courseList = ref<any>([])
onMounted(async () => {
    const datas = {}
    const rea = await getCourse(datas);
    console.log(rea);

    if (rea.data.code === 0) {
        courseList.value.push(...rea.data.data.data)
    } else {
        return false
    }

});

</script>
    
<style scoped lang="scss">

.films {
    padding-bottom: 60px;
    padding-top: 0;

    .item {
        margin-top: 15px;
        padding-bottom: 10px;
        padding-top: 10px;
        display: flex;
        color: #797d82;
        font-size: 13px;
        border-bottom: 1px solid #e7d8d8;
        background-color: #fff;

        .left {
            width: 100px;
            height: 70px;
            margin-left: 20px;

            img {
                width: 90px;
                height: 70px;
            }
        }

        .middle {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            width: 50%;
            margin-left: 10px;

            div:nth-of-type(1) {
                color: #191a1b;
                font-size: 16px;
            }

            div:nth-of-type(3) {
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }

        .right {
            width: 20%;
            display: flex;
            align-items: center;
            margin-right: 10px;

            span {
                border: 1px solid rgb(108, 244, 106);
                background: rgb(108, 244, 106);
                color: #fff;
                border-radius: 10px;
                height: 25px;
                line-height: 25px;
                font-size: 13px;
                width: 50px;
                text-align: center;
            }
        }
    }
}
</style>
  